<?php
include("lib/connection.php");
require_once 'class/class_rewrite_link.php';
$rewrite_link = new rewrite_link();
$id = 1;
if (isset($_GET['id_blog'])) {
  $id = $_GET["id_blog"];
}
//Insert thread to table to count
$count = 1;
$sql = "SELECT * FROM threadcount WHERE thread_id=$id";
$query = mysqli_query($conn,$sql);
$row_count = mysqli_num_rows($query);
if ($row_count==0) {
  $sql = "INSERT INTO threadcount (thread_id,count) VALUES($id,$count)";
  mysqli_query($conn,$sql);
}else{
  $data = mysqli_fetch_array($query);
  $count += $data['count'];
  $sql = "UPDATE threadcount set count = $count WHERE thread_id=$id";
  mysqli_query($conn,$sql);
}
//Get thread details
$sql = "SELECT * FROM thread  WHERE thread_id=$id";
$query = mysqli_query($conn,$sql);
$data = mysqli_fetch_array($query);
$big_title_op = $rewrite_link->slug($data['title_op']);
$title = $data['title'].' - PHP Programing - PHP Development';
$short_content = $data['short_content'].' - PHP Programing - PHP Development';
$og_url = "http://".$_SERVER['SERVER_NAME']."/".$big_title_op."-".$id.".html";
$cat_id = $data["cat_id"];
?>
<?php 
include 'inc/top.php';
include ("inc/ads-top.php");
?>
    <div class="row">
        <div class="col-sm-9">
  			<div class="bs-example">
  				<div class="blog-post">
            <h1 class="blog-post-title" style="padding-top:10px;font-size:40px;"><?php echo $data["title"]; ?></h2>
            <p class="blog-post-meta"> <?php echo $data["inp_date"];?> by <a href="#"><?php echo $data["upd_user"] ?></a></p>
            <hr>
            <p><?php //echo $data["short_content"]; ?></p>
            <?php
              echo $data["content"];
            ?>
            <!-- <hr style="height:1px;border:none;color:#333;background-color:#333;"> -->
            <h5 align="right">Nguon : <a href="http://kungfuphp.com" title="lap trinh php kungfuphp"> kungfuphp.com</a></h5>
            <hr>
            <p><font color="green"><b>Bạn còn băn khoăn vì chưa hiểu rõ vấn đề? Hãy tham gia vào <a href="http://kungfuphp.com/kungfuforum" title="kungfuphp forum">diễn đàn Kungfu PHP</a> để được cộng đông giúp đỡ nhé</b></font></p>
            <p align="right"><font color="red">Ghi rõ nguồn <b>http://kungfuphp.com</b> khi bạn phát hành thông tin trên website này</font></p>
            <!-- Kungfuphp BEGIN -->
            <div class="row" align="center" style="margin-bottom:10px;">
              <div class="a2a_kit a2a_kit_size_32 a2a_default_style" style="float:right">
              <a class="a2a_dd" href="https://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fkungfuphp.com%2F<?php echo $big_title_op; ?>-<?php echo $id; ?>.html&amp;linkname=kungfu%20php"></a>
              <a class="a2a_button_facebook"></a>
              <a class="a2a_button_twitter"></a>
              <a class="a2a_button_google_plus"></a>
              </div>
               <span style="float:right">Click để chia sẽ bài viết ~~>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
            </div>
            <script type="text/javascript">
            var a2a_config = a2a_config || {};
            a2a_config.linkname = "kungfu php";
            a2a_config.linkurl = "http://kungfuphp.com/<?php echo $big_title_op ?>-<?php echo $id; ?>.html";
            </script>
            <script type="text/javascript" src="//static.addtoany.com/menu/page.js"></script>
            <!-- Kungfuphp END -->
            <div align="center" class="row">   
              <div class="fb-comments" data-href="<?php echo $og_url; ?>" data-numposts="10" data-colorscheme="light" width="100%"></div>
            </div>
            <em>Bài viết liên quan</em>
            <?php
              $sql = "SELECT * FROM thread  WHERE cat_id=$cat_id";
              $query = mysqli_query($conn,$sql);
              
            ?>
            <ul>
              <?php
              while ($data = mysqli_fetch_array($query)) {
                $id_blog = $data['thread_id'];
                $title = $data['title'];
                $title_op =  $rewrite_link->slug($data['title_op']);
                $domain = $_SERVER['SERVER_NAME'];
                echo "<li><a href='http://$domain/$title_op-$id_blog.html'>$title</a></li>";
              }
              ?>
            </ul>
           
          </div>
  			</div>
        </div>

		<?php include 'inc/sidebar.php';?>

      </div>
  
  <?php include 'inc/footer.php';?>
   </div>